document.addEventListener('DOMContentLoaded', () => {
  var chartDom = document.getElementById('main');
  var myChart = echarts.init(chartDom);
  var option;

  option = {
    title: {
      text: '体温、温湿度曲线',
      textStyle: {
        color: '#c2e8ff'
      }
    },
    textStyle: {
      color: '#c2e8ff'
    },
    tooltip: {
      trigger: 'axis'
    },
    legend: {
      data: ['人体体温', '室内温度', '室内湿度'],
      textStyle: {
        color: '#c2e8ff'
      },
    },
    toolbox: {
      feature: {
        saveAsImage: {}
      }
    },
    grid: {
      left: '3%',
      right: '4%',
      bottom: '3%',
      containLabel: true
    },
    xAxis: [
      {
        type: 'category',
        boundaryGap: false,
        data: ['00:00', '03:00', '06:00', '09:00', '12:00', '15:00', '18:00', "21:00"]
      }
    ],
    yAxis: [
      {
        name: '温度 ℃',
        type: 'value',
        min: 10,
        max: 40,
        position: "left",
        axisLabel: {
          formatter: '{value}',
        },
        splitLine: {
          show: false
        }
      }, {
        name: "湿度 %RH",
        type: "value",
        min: 30,
        max: 80,
        position: "right",
        formatter: "{value}%",
        axisLabel: {
          formatter: '{value}',
        },
        itemStyle: {
          color: "#ffd07a"
        },
        splitLine: {
          show: false
        }
      }
    ],
    series: [
      {
        name: '人体体温',
        type: 'line',
        data: [36.5, 36.7, 36.1, 36.2, 36.7, 36.5, 36.3, 36.3],
        yAxisIndex: 0
      },
      {
        name: '室内温度',
        type: 'line',
        data: [30, 28, 27, 27, 26, 24, 26, 26],
        yAxisIndex: 0
      },
      {
        name: '室内湿度',
        type: 'line',
        data: [50, 52, 52, 57, 56, 55, 51, 59],
        yAxisIndex: 1
      }
    ]
  };

  option && myChart.setOption(option);
})


let get_data = () => {
  const body = []
  const tem = []
  const hum = []
  var xhr = new XMLHttpRequest();// 创建对象
  var url = "";
  xhr.open("POST", url, true);

  xhr.onreadystatechange = function ()// 当状态发生变化
  {
    if (xhr.readyState === 4 && xhr.status === 200)
    //响应正文:xhr.responseText
    {
      // var z = (xhr.responseText).split(' ')
      // console.log(z);

    }
  }
  xhr.send("get");  // 发送消息
}